package com.google.samples.apps.databinging.recycler

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.recyclerview.widget.LinearLayoutManager
import com.google.samples.apps.databinging.R
import com.google.samples.apps.databinging.binding.Book
import kotlinx.android.synthetic.main.activity_recycler.*

class RecyclerActivity : AppCompatActivity() {

    val bookAdapter: BookAdapter by lazy { BookAdapter(arrayListOf()) }

    val qBookAdapter: QBookAdapter by lazy { QBookAdapter() }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_recycler)
        recyclerView.run {
            layoutManager = LinearLayoutManager(this@RecyclerActivity)
//            adapter = bookAdapter
            adapter = qBookAdapter
        }

        val list = arrayListOf(
            Book("胞体", "狗蛋", 5),
            Book("额我发", "违法", 3),
            Book("士大夫", "二分", 25),
            Book("是否娃娃", "无非是", 1)
        )
//        bookAdapter.list.addAll(list)
//        bookAdapter.notifyDataSetChanged()

        qBookAdapter.setList(list)
    }
}